layui.use(['form', 'table', 'laypage'], function () {
    var form = layui.form,
        table = layui.table,
        laypage = layui.laypage;

    function getMid(){
        return JSON.parse(sessionStorage.getItem("manageInfo")).mid;
    }
    let vm = new Vue({
        el: "#dd",
        data: {
            mno: "",
            mrole: '',
            login_success: '',
            mroleArr: [{roleId: 0, roleName: "一般管理员"}, {roleId: 1, roleName: "超级管理员"}]
        },
        methods: {
            addBtn(){
                let mid = getMid();
                console.log(mid);
                let that = this;
                if(!this.mrole){
                    layer.msg("请选择管理员级别",{icon:2,time:2000});
                    return false;
                }
                if(!this.mno){
                    layer.msg("请输入新增管理员账号",{icon:2,time:2000});
                    return false;
                }
                $.ajax({
                    url:"/future/manager/pushManager/"+mid,
                    type:"POST",
                    data:JSON.stringify({
                        mno:that.mno,
                        mrole:that.mrole
                    }),
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    async:false,
                    success(res){
                        if(res.code=="10101"){
                            sessionStorage.setItem("manageInfo",null);
                            window.parent.location.reload();
                            return false;
                        }
                        layer.msg(res.message,{time:2000});
                    },error:function (err){
                        layer.alert(err);
                    }
                })
            }
        }
    })

    form.on("select(mrole)", function () {
        vm.$data.mrole = $("#mrole").val();
    })
    form.on("select(login_success)", function () {
        vm.$data.login_success = $("#login_success").val();
    })
    form.render();
});